// pages/coursesdata/coursesdata.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  callFunction(){
    wx.cloud.callFunction({
      name:'sum',
      data:{
        a:6,
        b:8
      },
      success(e){
        console.log(e);
      }
    })
  },
  cloudUploadData(){
    wx.chooseImage({
      count: 1,
      success: (result) => {
        let filePath = result.tempFilePaths[0]
        console.log(filePath);
        wx.cloud.uploadFile({
          filePath: filePath,
          cloudPath:'豆瓣电影/icons/菊花.png',//云文件名，上传后的云存储文件名
          success:e=>{
            console.log(e);
          }
        })
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },
  deleteData(){
    const db = wx.cloud.database()
    const courses = db.collection('courses')
    courses.doc('ca780ad5626a046e006a86cf216de844')
    .remove({
      success:e=>{
        console.log(e);
      },
      fail:e=>{
        console.log(e);
      }
    })
  },
  updataData() {
    const db = wx.cloud.database()
    const courses = db.collection('courses')
    courses.doc('6d85a2b96268f1360082f69f41e32866')
      .update({
        data:{
          price: 38
        },
        success:e=>{
          console.log(e);
        }
      })
  },
  getData() {
    //获取数据库的引用
    const db = wx.cloud.database()
    const courses = db.collection('courses')
    courses.get({
      success: e => {
        console.log(e);
      }
    })
  },
  getDataBywhere() {
    const db = wx.cloud.database()
    const courses = db.collection('courses')
    const _ = db.command
    courses.where({
      price: _.gte(10).and(_.lte(25)),
      id: _.gt(1)
    })
      .get({
        success: e => {
          console.log(e.data);
        }
      })

  },
  addData() {
    const db = wx.cloud.database()
    const courses = db.collection('courses')
    courses.add({
      data: {
        id: 3,
        name: '微信小程序',
        price: 22.8
      },
      success: e => {
        console.log(e);
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})